package org.neptune.service.config;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

import org.neptune.common.constant.NeptuneConstant;
import org.neptune.service.util.WebUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @author lwl
 * @date 2019/11/22 15:43
 */
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {

	@Bean
	public ServerEndpointExporter serverEndpointExporter() {
		return new ServerEndpointExporter();
	}

	@Override
	public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
			HandshakeResponse response) {
		// 将用户信息存储到socket的配置里
		sec.getUserProperties().put(NeptuneConstant.WEBSOCKET_USER, WebUtil.getLoginUser());
		super.modifyHandshake(sec, request, response);
	}
}
